package com.scuthnweb.action.authority;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.scuthnweb.domain.Role;
import com.scuthnweb.tool.QueryValidateModule;

/**
 * 
 * @author YJ.Huang
 *
 */
public class ValidateRoleAuthorityInterceptor  extends AbstractInterceptor implements ErrorCode{
	
	private QueryValidateModule queryValidateModule;
	
	@Override
	public String intercept(ActionInvocation action) throws Exception {
		ActionContext ctx  = ActionContext.getContext();
		Integer uid = (Integer)ctx.getSession().get("user_id");
		Role role = this.queryValidateModule.userWholeRole(uid);
		if(role==null)
			return NO_ACTIVATE;
		else{
			if(role.getAuthority().intValue()==0)
				return NO_AUTH;
			else
				return action.invoke();
		}
	}

	public QueryValidateModule getQueryValidateModule() {
		return queryValidateModule;
	}

	public void setQueryValidateModule(QueryValidateModule queryValidateModule) {
		this.queryValidateModule = queryValidateModule;
	}

}
